<%-- 
    Document   : readPurchases
    Created on : 2 juin 2012, 01:15:31
    Author     : isen
--%>

<%@page import="model.CartContent"%>
<%@page import="java.util.ArrayList"%>
<%@page import="model.Transactions"%>
<%@page import="persistence.PersistenceImplementation"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Purchases</title>
    </head>
    <body>
        <h1>Here you can see all the purchases:</h1>


        <%
            ArrayList<Integer> listIds = PersistenceImplementation.getJDBCPersistenceManager().getTransactionIds();
        %>       


        <% for (int i = 0; i < listIds.size(); i++) {
                Transactions transaction = PersistenceImplementation.getJDBCPersistenceManager().getTransaction(listIds.get(i));
                ArrayList<CartContent> cartContents = PersistenceImplementation.getJDBCPersistenceManager().getCartContents(transaction.getCartid());
        %>
                           
    <center>
            <h1>Purchase <%=i+1%>: </h1>
            <table border="1" cellspacing="5">

                    <tbody>
                        <tr>
                            <td>Client name</td>
                            <td><%= transaction.getClientName()%></td>
                        </tr>
                        <tr>
                            <td>Address</td>
                            <td><%=PersistenceImplementation.getJDBCPersistenceManager().getAdress(transaction.getClientName())%></td>
                        </tr>
                        <tr>
                            <td>Total price</td>
                            <td><%= transaction.getFinalPrice()%></td>
                        </tr>
                        <tr>
                            <td>Payment form</td>
                            <td><%=PersistenceImplementation.getJDBCPersistenceManager().getPaymentform(transaction.getClientName())%></td>
                        </tr>
                        <tr>
                            <td>Date</td>
                            <td><%=transaction.getDate()%></td>
                        </tr>
                    </tbody>
                </table><br />

  
                   <% if (!cartContents.isEmpty()){ %>
                               
                                             
                        <% for (int j = 0; j < cartContents.size(); j++) {%>                   
                            <table  border="1" cellspacing="5">
                                <tbody>
                                    <tr><td>Product name</td><td>Quantity</td></tr>
                      
                                    <tr>
                                        <td><%= cartContents.get(j).getProductname()%></td>
                                        <td><%= cartContents.get(j).getQuantity()%></td>
                                    </tr>
                                <tbody>
                            </table>
                            <%}%> 
                    <%}%>    
         <%}%>

    </center>
        <br /> <%@include file="/WEB-INF/include/menuAdministrador.jsp" %>
         
    </body>
</html>
